import { Component, HostListener, OnInit } from '@angular/core';
import { ToptipsService } from 'ngx-weui';
import { I18nService } from './core/i18n/i18n.service';
import { Title } from '@angular/platform-browser';

@Component({
	selector: 'app-root',
	templateUrl: './app.component.html',
	styleUrls: ['./app.component.css'],
})

export class AppComponent {
	title = 'app';
	windowWidth: number;
	constructor(private srv: ToptipsService, i: I18nService,private titleService: Title) {
		i.get(["title"]).subscribe(res => {
			this.titleService.setTitle(res['title'])
    	})
        this.getFontSize(window.document.documentElement);
        const imgObj = new Image(); // 创建图片对象
        imgObj.src = '../../assets/images/usercenter/input.jpg';
        imgObj.style.display = 'none';
        document.body.append(imgObj);
	}
	@HostListener('window:resize', ['$event'])
	onResize(event) {
		this.getFontSize(window.document.documentElement);
	}
	getFontSize(docEl) {
		const clientWidth = docEl.clientWidth;
		if (!clientWidth) {
			return;
		}
		if (clientWidth >= 750) {
			docEl.style.fontSize = '16px';
		} else if (clientWidth <= 320) {
			docEl.style.fontSize = '7px';
		} else {
			docEl.style.fontSize = 16 * (clientWidth / 750) + 'px';
		}
	}
}
